package com.darthsith.droidathome.core.service.impl;

import java.util.ArrayList;

import org.springframework.stereotype.Service;

import com.darthsith.droidathome.core.model.ArduinoBoard;
import com.darthsith.droidathome.core.model.Sensor;
import com.darthsith.droidathome.core.service.ArduinoService;

@Service
public class ArduinoServiceImplFake implements ArduinoService {

	@Override
	public ArduinoBoard getArduinoBoardStatus(String id) {
		return createFakeBoard(id);
	}

	@Override
	public ArrayList<ArduinoBoard> getSystemStatus() {
		ArrayList<ArduinoBoard> system=new ArrayList<ArduinoBoard>();
		for (int i=0; i<=2; i++) {
			int id=0+(int)(Math.random()*255);
			ArduinoBoard arduinoBoard=createFakeBoard(new Integer(id).toString());
			system.add(arduinoBoard);
		}
		return system;
	}

	@Override
	public Sensor getSensor(String id, int pin) {
		return createFakeSensor(id, pin);
	}	
	
	private ArduinoBoard createFakeBoard(String id) {
		ArduinoBoard arduinoBoard=new ArduinoBoard();
		ArrayList<Sensor> sensors=new ArrayList<Sensor>();
		for (int i=0; i<5; i++) {
			int pin=1+(int)(Math.random()*13);
			Sensor s=createFakeSensor(id, pin);
			sensors.add(s);
		}
		arduinoBoard.setSensors(sensors);
		arduinoBoard.setIpAddress("192.168.0."+id);
		arduinoBoard.setName("Camera");
		arduinoBoard.setMacAddress("0xDE,0xAD,0xBE,0xEF,0xFE,0xED");
		return arduinoBoard;
	}
	
	private Sensor createFakeSensor(String id, int pin) {
		Sensor sensor=new Sensor();
		sensor.setIpAddress("192.168.0."+id);
		sensor.setName("luce1");
		sensor.setPin(pin);
		sensor.setType("light");
		sensor.setValue("0");
		sensor.setStatus("active");
		return sensor;
	}

	@Override
	public void updateSensor(Sensor sensor) {

	}
	
}
